package com.example.ui.activity

import android.os.Bundle
import android.widget.HorizontalScrollView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.R

class Day02Activity : AppCompatActivity() {

    var scrollview: HorizontalScrollView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_day02)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        scrollview = findViewById<HorizontalScrollView>(R.id.scrollview)
        scrollview?.setOnScrollChangeListener(this)
    }
}

private fun HorizontalScrollView.setOnScrollChangeListener(day02Activity: Day02Activity) {
    this.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
        day02Activity.scrollview?.scrollTo(scrollX, scrollY)
    }
}
